package com.ken.apollo.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ken.apollo.domain.query.ProductClassifyQuery;
import com.ken.apollo.mapper.ProductClassifyMapper;
import com.ken.apollo.domain.entity.ProductClassify;
import com.ken.apollo.service.LanguageService;
import com.ken.apollo.service.ProductClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 产品分类表(ProductClassify)表服务实现类
 *
 * @author makejava
 * @since 2025-06-09 20:11:41
 */
@Service
public class ProductClassifyServiceImpl extends ServiceImpl<ProductClassifyMapper, ProductClassify> implements ProductClassifyService {

    @Autowired
    private LanguageService languageService;

    /**
     * 根据请求查询分类列表
     *
     * @param productClassifyQuery
     * @return
     */
    @Override
    public List<ProductClassify> queryAll(ProductClassifyQuery productClassifyQuery) {
        List<ProductClassify> productClassifyList = this.lambdaQuery()
                .eq(ObjectUtil.isNotNull(productClassifyQuery.getLanguageId()), ProductClassify::getLanguageId, productClassifyQuery.getLanguageId())
                .list();

        if (ObjectUtil.isEmpty(productClassifyList)) return List.of();

        //关联查询语言类型
        productClassifyList.stream().forEach(productClassify -> {
            productClassify.setLanguageName(languageService.getById(productClassify.getLanguageId()).getLanguageName());
        });

        return productClassifyList;
    }
}

